/**
 * 
 */
package com.whu.waterworks.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.orm.hibernate4.HibernateTemplate;

import com.whu.waterworks.dao.AntissepticDao;
import com.whu.waterworks.model.Antisseptic;
import com.whu.waterworks.model.Antisseptic;

/**
 * @author： Joymin
 * @date：2016-4-5 下午9:03:55
 * 说明: 
 */
public class AntissepticDaoImpl implements AntissepticDao{
	private HibernateTemplate hibernateTemplate;
	
	public HibernateTemplate getHibernateTemplate() {
		return hibernateTemplate;
	}

	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}

	/* (non-Javadoc)
	 * @see com.whu.waterworks.dao.AntissepticDao#saveAntisseptic(com.whu.waterworks.model.Antisseptic)
	 */
	@Override
	public boolean saveAntisseptic(Antisseptic norm) {
		// TODO Auto-generated method stub
		hibernateTemplate.save(norm);
		return true;
	}

	/* (non-Javadoc)
	 * @see com.whu.waterworks.dao.AntissepticDao#updateAntisseptic(com.whu.waterworks.model.Antisseptic)
	 */
	@Override
	public boolean updateAntisseptic(Antisseptic norm) {
		// TODO Auto-generated method stub
		hibernateTemplate.merge(norm);
		return true;
	}

	/* (non-Javadoc)
	 * @see com.whu.waterworks.dao.AntissepticDao#delAntisseptic(com.whu.waterworks.model.Antisseptic)
	 */
	@Override
	public boolean delAntisseptic(Antisseptic norm) {
		// TODO Auto-generated method stub
		hibernateTemplate.delete(norm);
		return true;
	}

	/* (non-Javadoc)
	 * @see com.whu.waterworks.dao.AntissepticDao#getLimitedAntisseptic()
	 */
	@Override
	public Antisseptic getLimitedAntisseptic() {
		// TODO Auto-generated method stub
		@SuppressWarnings("unchecked")
		ArrayList<Antisseptic> rs =(ArrayList<Antisseptic>) hibernateTemplate.find("from Antisseptic _Antisseptic where _Antisseptic.type='1'");
		if(null!=rs && rs.size()>0){
			System.out.println("hahah");
			return rs.get(0);
		}
		return null;
	}

	/* (non-Javadoc)
	 * @see com.whu.waterworks.dao.AntissepticDao#getAntissepticById(java.lang.String)
	 */
	@Override
	public Antisseptic getAntissepticById(String id) {
		// TODO Auto-generated method stub
		@SuppressWarnings("unchecked")
		ArrayList<Antisseptic> rs =(ArrayList<Antisseptic>) hibernateTemplate.find("from Antisseptic _Antisseptic where _Antisseptic.id='"+id+"'");
		if(null!=rs && rs.size()>0){
			return rs.get(0);
		}
		return null;
	}

	/* (non-Javadoc)
	 * @see com.whu.waterworks.dao.AntissepticDao#getAntissepticByIdAndTime(java.lang.String, java.lang.String)
	 */
	@Override
	public List<Antisseptic> getAntissepticByIdAndTime(String waterPlantId,
			String time) {
		// TODO Auto-generated method stub
		@SuppressWarnings("unchecked")
		ArrayList<Antisseptic> rs =(ArrayList<Antisseptic>) hibernateTemplate.find("" +
				"from Antisseptic _Antisseptic where _Antisseptic.waterplantId='"+waterPlantId+"' and _Antisseptic.time='"+time+"'");
		if(null!=rs && rs.size()>0){
			return rs;
		}
		return null;
	}
//zhoululu
	@Override
	public List<Antisseptic> getAntisseptics(String code, String startTime,
			String endTime) {
     @SuppressWarnings("unchecked")
	ArrayList<Antisseptic> antisseptics=(ArrayList<Antisseptic>) hibernateTemplate.find("from Antisseptic ap where ap.waterplantId='"+code+"' and ap.time between '"+
    		 startTime+"' and '"+endTime+"'");
		return antisseptics;
	}
	
}
